package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.emuns.Operator;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;

	public class Command
	{
		public function Command()
		{
			
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var chara:Character = data as Character;
			var oper:int = node.arguments[0];
			var val:String = node.arguments[1];
			var rlt:Boolean = false;
			
			var isActive:Boolean = chara.commandManager.isActive(val);
			switch(oper)
			{
				case Operator.Equals:
				{
					return isActive; 
					break;
				}
				case Operator.NotEquals:
				{
					return !isActive; 
					break;
				}
			}
			return rlt;
		}
		
		public static function parse(state:ParseState):Node
		{
			var operator:int = state.currentOperator;
			if(operator != Operator.Equals && operator != Operator.NotEquals)
			{
				return null;
			}
			state.tokenIndex++;
			
			var text:String = state.currentText;
			if(text == null)
			{
				return null;
			}
			
			state.tokenIndex++;
			state.baseNode.arguments.push(operator);
			state.baseNode.arguments.push(text);
			return state.baseNode;
		}
	}
}